package com.platform.util;

import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.platform.entity.QueryTrackResp;
import com.platform.util.wechat.WechatRefundApiResult;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.spec.AlgorithmParameterSpec;
import java.util.List;
import java.util.Map;
import java.util.Properties;


public class test {
	private static SSLConnectionSocketFactory sslcsf;
	public static String decrypt(String sessionkey, String ivdata, String encrypdata) throws Exception {
		byte[] encData = Base64.decode(encrypdata);
		byte[] iv = Base64.decode(ivdata);
		byte[] key = Base64.decode(sessionkey);
		AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
		Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
		SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
		cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
		//解析解密后的字符串
		return new String(cipher.doFinal(encData),"UTF-8");
	}
	public static void main(String[] args) throws Exception {

//		String decstr = decrypt("d10lRQuqAdjwhI/Xp0RHHg==", "f277eKhAvanTwiq27CMxqA==", "P/yZP+1o++t/K4SQJqr6ja4bexJM9NolcmMI2QPvp3PoCQ1RTu5DUbUrOeXFL3OLYDw0xjvYxeoo+O7EuAVer0J4qxsmtsATAa3UKSE2AlKCTZ9rDow/Tsx+LP+RnbSDZYGKCTKwdmLs+i4C8v8+yQACL5eKSDHuKEco/dOTJmV/P8+X70nH5Rkne20SMqLAzXeeiX74ow1uLYd5Mp2bjQ==");
//
//		System.out.println(decstr);

		JSONObject jsonObject = JSON.parseObject("{\"message\":\"ok\",\"nu\":\"SF1194516552073\",\"ischeck\":\"1\",\"condition\":\"F00\",\"com\":\"shunfeng\",\"status\":\"200\",\"state\":\"3\",\"data\":[{\"time\":\"2020-09-26 14:28:08\",\"ftime\":\"2020-09-26 14:28:08\",\"context\":\"[北京市]您的快件已签收，如有疑问请电联小哥【刘昶彤，电话：17812176739】。疫情期间顺丰每日对网点消毒、小哥每日测温、配戴口罩，感谢您使用顺丰，期待再次为您服务。（主单总件数：1件）\"},{\"time\":\"2020-09-26 13:58:00\",\"ftime\":\"2020-09-26 13:58:00\",\"context\":\"[北京市]快件交给刘昶彤,正在派送途中（联系电话：17812176739,顺丰已开启“安全呼叫”保护您的电话隐私,请放心接听！）（主单总件数：1件）\"},{\"time\":\"2020-09-26 13:38:25\",\"ftime\":\"2020-09-26 13:38:25\",\"context\":\"[北京市]快件交给刘昌昊,正在派送途中（联系电话：18233000792,顺丰已开启“安全呼叫”保护您的电话隐私,请放心接听！）（主单总件数：1件）\"},{\"time\":\"2020-09-26 12:51:21\",\"ftime\":\"2020-09-26 12:51:21\",\"context\":\"[北京市]快件到达 【北京昌平天通苑营业点】\"},{\"time\":\"2020-09-26 11:57:05\",\"ftime\":\"2020-09-26 11:57:05\",\"context\":\"[北京市]快件已发车\"},{\"time\":\"2020-09-26 11:56:54\",\"ftime\":\"2020-09-26 11:56:54\",\"context\":\"[北京市]快件在【北京南法信中转场】已装车,准备发往 【北京昌平天通苑营业点】\"},{\"time\":\"2020-09-26 10:45:15\",\"ftime\":\"2020-09-26 10:45:15\",\"context\":\"[北京市]快件到达 【北京南法信中转场】\"},{\"time\":\"2020-09-25 05:47:33\",\"ftime\":\"2020-09-25 05:47:33\",\"context\":\"[成都市/资阳市/眉山市]快件已发车\"},{\"time\":\"2020-09-25 02:07:37\",\"ftime\":\"2020-09-25 02:07:37\",\"context\":\"[成都市/资阳市/眉山市]快件在【成都空港中转场】已装车,准备发往 【北京南法信中转场】\"},{\"time\":\"2020-09-25 01:50:37\",\"ftime\":\"2020-09-25 01:50:37\",\"context\":\"[成都市/资阳市/眉山市]快件到达 【成都空港中转场】\"},{\"time\":\"2020-09-25 01:12:01\",\"ftime\":\"2020-09-25 01:12:01\",\"context\":\"[成都市/资阳市/眉山市]快件已发车\"},{\"time\":\"2020-09-25 01:00:40\",\"ftime\":\"2020-09-25 01:00:40\",\"context\":\"[成都市/资阳市/眉山市]快件在【成都双流中转场】已装车,准备发往 【成都空港中转场】\"},{\"time\":\"2020-09-25 00:07:12\",\"ftime\":\"2020-09-25 00:07:12\",\"context\":\"[成都市/资阳市/眉山市]快件到达 【成都双流中转场】\"},{\"time\":\"2020-09-24 20:52:48\",\"ftime\":\"2020-09-24 20:52:48\",\"context\":\"[成都市/资阳市/眉山市]快件已发车\"},{\"time\":\"2020-09-24 20:38:31\",\"ftime\":\"2020-09-24 20:38:31\",\"context\":\"[成都市/资阳市/眉山市]快件在【成都市金牛区兴盛世家营业点】已装车,准备发往 【成都双流中转场】\"},{\"time\":\"2020-09-24 15:45:21\",\"ftime\":\"2020-09-24 15:45:21\",\"context\":\"[成都市/资阳市/眉山市]顺丰速运 已收取快件\"}]}\n");
		jsonObject.put("kefu","955388");
		QueryTrackResp q = JSON.toJavaObject(jsonObject,QueryTrackResp.class);
		//jsonObject.get("data");
		System.out.println(q.getData().get(0).getFtime()+" "+"kefu:"+q.getKefu());
//		RestTemplate restTemplate=new RestTemplate();
//		String s="http://poll.kuaidi100.com/poll/query.do?customer=8CB0DD11911F3E5B49D6BD35588CFB9D&sign=9033F64225B3E06C7DA99CF716C97EBF&param={\"com\":\"shunfeng\",\"from\":\"\",\"num\":\"SF1194516552073\",\"order\":\"desc\",\"phone\":\"18518259888\",\"resultv2\":\"0\",\"show\":\"0\",\"to\":\"\"}\n";
//		System.out.println(restTemplate.getForObject(s, QueryTrackResp.class));
//		Properties properties = new Properties();
//		// 使用ClassLoader加载properties配置文件生成对应的输入流
//		InputStream in = RedisUtils.class.getClassLoader().getResourceAsStream("j2cache.properties");
//		System.out.println(in);
//		try {
//			properties.load(in);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		//获取key对应的value值
//		String adds = properties.getProperty("redis.adds");
//		Map<String, Object> map = YamlUtils.yamlHandler(new ClassPathResource("application.yml"));
//		System.out.println(map.get("wx.certName"));
//		try {
//			KeyStore keyStore = KeyStore.getInstance("PKCS12");
//			Thread.currentThread().getContextClassLoader();
//			InputStream instream = new WechatRefundApiResult().getClass().getResourceAsStream(String.valueOf(map.get("wx.certName")));
//			try {
//				keyStore.load(instream, String.valueOf(map.get("wx.mchId")).toCharArray());
//			} finally {
//				instream.close();
//			}
//			SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, String.valueOf(map.get("wx.mchId")).toCharArray()).build();
//			sslcsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
	}
}
